<template>
    <div id="da">
        <div class="sear">
            <div class="se">
                <van-icon name="search" />
                <p @click="$router.push('/serch')">搜索课程</p>
            </div>
        </div>
        <div class="shaixuan">
            <van-dropdown-menu>
                <van-dropdown-item title="分类" ref="fen">
                    <div class="fen">
                        <button class="c" @click="chong">重置</button>
                        <button class="q" @click="chong">确定</button>
                    </div>
                </van-dropdown-item>
                <van-dropdown-item v-model="from.order_by" :options="option" title="排序" />
                <van-dropdown-item title="筛选" ref="item">
                    <ul class="clear">
                        <li v-for="(item,index) in shailist" :key="index" :class="{ 'red' :from.course_type==item.id }" @click="editcid(item.id)">
                            <p>{{item.name}}</p>
                        </li>
                    </ul>
                </van-dropdown-item>
            </van-dropdown-menu>
        </div>
        <div>
            <div v-if="list" class="dis">
                <keList :pagelists='list'></keList>
            </div>
            <div v-else>
                <van-empty class="custom-image" image="http://120.53.31.103:86/img/empty.0d284c2e.png" description="暂无课程" />
            </div>
        </div>
    </div>
</template>
<script>
import { shai, search } from '@/api/user.js'
import keList from '@/components/kelist'
export default {
    components: { keList },
  data() {
    return {
      option: [
        { text: '综合排序', value: 0 },
        { text: '最新', value: 1 },
        { text: '最热', value: 2 },
        { text: '价格从低到高', value: 3 },
        { text: '价格从高到低', value: 4 }
      ],
      shailist: [],
      from: {
        page: 1,
        limit: 50,
        course_type: 0,
        order_by: 0,
        is_vip: 0
      },
      list:[]
    }
  },
  methods: {
    async getshai() {
      let { data: data } = await shai()
      this.shailist = data.data.appCourseType
      console.log(this.shailist)
    },
    editcid(i) {
      this.from.course_type = i 
      this.$refs.item.toggle()
    },
    chong() {
      console.log(44)
      this.$refs.fen.toggle()
    },
    async getlist() {
      console.log(this.from)
      let { data: data } = await search(this.from)
      this.list=data.data
      console.log(data.data);
    }
  },
  watch: {
    from: {
      handler(val) {
        this.getlist()
      },
      deep: true
    }
  },
  created() {
    this.getshai()
    this.getlist()
  }
}
</script>
<style lang="scss" scoped>
#da {
  background: #f7f8fa;
  height: 100%;
}
.sear {
  background: #fff;
  padding: 5px 15px;
  .se {
    background: white;
    border: 1px solid #d9d9d9;
    padding: 10px;
    border-radius: 25px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    color: #b7b7b7;
    p {
      margin-left: 10px;
    }
  }
}
/deep/.van-cell {
  .van-cell__value {
    display: none;
  }
  .van-cell__title {
    text-align: center;
  }
}
.fen {
  width: 100%;
  padding: 20px 15px;
  box-sizing: border-box;
  background: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  button {
    width: 48%;
    height: 32px;
    border-radius: 5px;
    font-size: 14px;
  }
  .c {
    background: white;
    border: 1px solid #d9d9d9;
    color: #595959;
  }
  .q {
    color: #fff;
    background: #e60012;
    border: none;
  }
}
/deep/.van-dropdown-menu__bar {
  box-shadow: none;
  border-bottom: 1px solid #eaeaea;
}
.clear {
  display: flex;
  flex-wrap: wrap;
  padding: 10px 15px;
  align-items: center;
  li {
    text-align: center;
    width: 18%;
    background: #f5f5f5;
    padding: 6px 6.2px;
    margin-right: 15px;
    color: #646464;
    font-size: 14px;
    margin-top: 7px;
    margin-bottom: 7px;
  }
  .red {
    color: #e60012;
    background: #ebeefe;
  }
  li:nth-child(4n + 0) {
    margin-right: 0;
  }
}
.dis{
    padding: 15px;
}
</style>


